package com.project.controller;

import com.project.entity.qo.OrderQo;
import com.project.entity.vo.OrderVo;
import com.project.result.ResponseResult;
import com.project.result.ResultCode;
import com.project.service.impl.OrderServiceImpl;
import com.project.utils.ShiroUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chen
 * @date 2022/3/29
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderServiceImpl orderService;

    /**
     * 添加订单
     *
     * @param orderQo
     * @return
     */
    @PutMapping("/insert")
    public ResponseResult<ResultCode> insertOrder(@RequestBody OrderQo orderQo) {
        return orderService.addOrder(orderQo);
    }

    /**
     * 查询所有订单
     *
     * @return
     */
    @GetMapping("/select/order")
    public ResponseResult<List<OrderVo>> selectOrder() {
        return orderService.selectOrder();
    }

    /**
     * 获取前端发送过来的订单编号
     *
     * @param orderId
     */
    @GetMapping("/get/order/id")
    public ResponseResult<ResultCode> getOrderId(Long orderId) {
        ShiroUtils.getSession().setAttribute("orderId", orderId);
        return ResponseResult.success(ResultCode.SUCCESS);
    }

    /**
     * 根据条件查询(根据名字可模糊查询)
     * @param orderQo
     * @return
     */
    @GetMapping("/select/by/order")
    public ResponseResult<List<OrderVo>> selectByOrder(@RequestBody OrderQo orderQo){
        return orderService.selectByOrder(orderQo);
    }

    /**
     * 分页查询
     * @param current
     * @return
     */
    @GetMapping("select/order/page")
    public ResponseResult<List<OrderVo>> selectOrderPage(Integer current){
        return orderService.selectOrderPage(current);
    }
}
